//
//  TrainingCertificationViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/22.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "TrainingCertificationViewController.h"
#import "UIImagePickerController+Edit.h"
#import "UICustomActionSheet.h"
#import "ScroButton.h"

@interface TrainingCertificationViewController ()
<UIActionSheetDelegate>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UITextField *nameTextField;//真实姓名
@property (strong, nonatomic) IBOutlet UITextField *phoneNumberTextField;//联系电话
@property(nonatomic,strong)ScroButton * sexButton;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonOne;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonTwo;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonThree;
@property (strong, nonatomic) IBOutlet UIButton *AddImageButtonFour;
@property (strong, nonatomic) IBOutlet UIButton *submitButton;
@property (strong, nonatomic) IBOutlet UIButton *backButton;
@property(nonatomic,strong)NSString * imageStrOne;
@property(nonatomic,strong)NSString * imageStrTwo;
@property(nonatomic,strong)NSString * imageStrThree;
@property(nonatomic,strong)NSString * imageStrFour;

@property (assign, nonatomic) NSInteger count;
@end

@implementation TrainingCertificationViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([self.muceStatus isEqualToString:@"1"] || [self.muceStatus isEqualToString:@"2"]) {
        [self updatelayout];
    } else if ([self.muceStatus isEqualToString:@"0"]) {
        [self.submitButton setTitle:@"提交审核" forState:UIControlStateNormal];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self initViewLayout];
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    _scroview.contentSize = flexibleSize(CGSizeMake(0, 600), NO);
    _submitButton.layer.masksToBounds = YES;
    _submitButton.layer.cornerRadius = 5*VerticalRatio();
    
    ScroButton * button = [[ScroButton alloc]initWithFrame:flexibleFrame(CGRectMake(90, 100, 48, 23), NO)];
    button.defaultColor = [UIColor colorWithRed:0.988 green:0.439 blue:0.035 alpha:1.000];
    button.selectedColor = [UIColor colorWithRed:0.063 green:0.506 blue:0.835 alpha:1.000];
    button.defaultTitle = @"女";
    button.selectedTitle = @"男";
    button.circleColor = [UIColor whiteColor];
    button.textColor = [UIColor whiteColor];
    button.textFont = [UIFont systemFontOfSize:15*VerticalTexeRatio()];
    button.ifSelected = YES;
    button.changeSelected = ^(BOOL ifSelected){
        
    };
    [self.scroview addSubview:button];
    _sexButton = button;
}

- (void)updatelayout {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor clearColor];
    view.frame = flexibleFrame(CGRectMake(90, 100, 48, 23), NO);
    view.tag = 1000;
    [self.scroview addSubview:view];
    [self.scroview bringSubviewToFront:view];
    
    self.nameTextField.text = [NSString stringWithFormat:@"%@",_dic[@"muceRealName"]];
    self.phoneNumberTextField.text = [NSString stringWithFormat:@"%@",_dic[@"mucePhone"]];
    NSString *muceGender = [NSString stringWithFormat:@"%@",_dic[@"muceGender"]];
    if ([muceGender isEqualToString:@"0"]) {
        _sexButton.ifSelected = YES;
    }else if ([muceGender isEqualToString:@"1"]) {
        _sexButton.ifSelected = NO;
    }
    
    NSString *msceIdcardFront = [NSString stringWithFormat:@"%@",self.dic[@"muceIdcardFront"]];
    if (msceIdcardFront && msceIdcardFront.length>0 && ![self.dic[@"mexpImage"] isEqual:[NSNull null]]) {
        [self.AddImageButtonOne sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceIdcardFront]] forState:UIControlStateNormal];
    }
    NSString *msceIdcardBack = [NSString stringWithFormat:@"%@",self.dic[@"muceIdcardBack"]];
    if (msceIdcardBack && msceIdcardBack.length>0 && ![self.dic[@"mexpImage"] isEqual:[NSNull null]]) {
        [self.AddImageButtonOne sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceIdcardBack]] forState:UIControlStateNormal];
    }
    NSString * images = [NSString stringWithFormat:@"%@",self.dic[@"muceLicence"]];
    images = [images substringToIndex:images.length];
    NSArray *imageArray = [NSArray array];
    imageArray = [[images componentsSeparatedByString:@","]mutableCopy];
    NSString *msceLicense = [NSString stringWithFormat:@"%@",imageArray[0]];
    if (msceLicense && msceLicense.length>0 && ![self.dic[@"mexpImage"] isEqual:[NSNull null]]) {
        [self.AddImageButtonOne sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceLicense]] forState:UIControlStateNormal];
    }
    NSString *msceQualification = [NSString stringWithFormat:@"%@",imageArray[1]];
    if (msceQualification && msceQualification.length>0 && ![self.dic[@"msceQualification"] isEqual:[NSNull null]]) {
        [self.AddImageButtonOne sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,msceQualification]] forState:UIControlStateNormal];
    }

    
    if ([self.muceStatus isEqualToString:@"1"]) {

        [self.submitButton setTitle:@"已通过" forState:UIControlStateNormal];
        self.nameTextField.userInteractionEnabled = NO;
        self.phoneNumberTextField.userInteractionEnabled = NO;
        [self.AddImageButtonOne setEnabled:NO];
        [self.AddImageButtonTwo setEnabled:NO];
        [self.AddImageButtonThree setEnabled:NO];
        [self.AddImageButtonFour setEnabled:NO];
    } else if ([self.muceStatus isEqualToString:@"2"]) {
        [self.submitButton setTitle:@"审核未通过，请重新提交" forState:UIControlStateNormal];
        UIView *subview  = [self.view viewWithTag:1000];
        [subview removeFromSuperview];
    }
}

- (IBAction)back:(id)sender {
    [self backBtn];
}



#pragma mark - 选择上传方式
- (IBAction)addImage:(UIButton *)sender {
    if (sender == _AddImageButtonOne) {
        
        _AddImageButtonOne.selected = YES;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonThree.selected = NO;
        _AddImageButtonFour.selected = NO;
        _count = 1;
    } else if (sender == _AddImageButtonTwo) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = YES;
        _AddImageButtonThree.selected = NO;
        _AddImageButtonFour.selected = NO;
        _count = 2;
    } else if (sender == _AddImageButtonThree) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonThree.selected = YES;
        _AddImageButtonFour.selected = NO;
        _count = 3;
    } else if (sender == _AddImageButtonFour) {
        
        _AddImageButtonOne.selected = NO;
        _AddImageButtonTwo.selected = NO;
        _AddImageButtonThree.selected = NO;
        _AddImageButtonFour.selected = YES;
        _count = 4;
    }
    [self choosePhoto];
}


#pragma mark - 相关证件
- (void)choosePhoto{
     PhotoPopView * photoPopView = [[PhotoPopView alloc]initWithcomplect:^(NSInteger index) {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        UICustomActionSheet* actionSheet = [[UICustomActionSheet alloc] initWithTitle:@"" delegate:nil buttonTitles:@[@"",@""]];
        
        [actionSheet setButtonColors:@[[UIColor clearColor]]];
        [actionSheet setBackgroundColor:[UIColor clearColor]];
        
        [actionSheet setSubtitle:@""];
        [actionSheet setSubtitleColor:[UIColor clearColor]];
        
        [actionSheet showInView:self.view];
        
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [actionSheet hideAlert];
        if (index == 0){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                if (_count == 1) {
                    
                    [self.AddImageButtonOne setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 2) {
                    
                    [self.AddImageButtonTwo setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 3) {
                    
                    [self.AddImageButtonThree setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 4) {
                    
                    [self.AddImageButtonFour setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (index == 1){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                if (_count == 1) {
                    
                    [self.AddImageButtonOne setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 2) {
                    
                    [self.AddImageButtonTwo setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 3) {
                    
                    [self.AddImageButtonThree setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 4) {
                    
                    [self.AddImageButtonFour setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
        
        
        
    }else {
        UIActionSheet *ss=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"" otherButtonTitles:@"", nil];
        [ss showInView:self.view];
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [ss dismissWithClickedButtonIndex:0 animated:YES];
        if (index == 0){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                if (_count == 1) {
                    
                    [self.AddImageButtonOne setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 2) {
                    
                    [self.AddImageButtonTwo setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 3) {
                    
                    [self.AddImageButtonThree setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 4) {
                    
                    [self.AddImageButtonFour setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (index == 1){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                if (_count == 1) {
                    
                    [self.AddImageButtonOne setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 2) {
                    
                    [self.AddImageButtonTwo setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 3) {
                    
                    [self.AddImageButtonThree setBackgroundImage:image forState:UIControlStateNormal];
                    
                } else if (_count == 4) {
                    
                    [self.AddImageButtonFour setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
        
        
    }
     }];
    [photoPopView show];
    
}

#pragma mark - 上传图片--------------------------
- (void) imageUpload:(int)numberImg:(UIImage *)imageImage{
    NSString *url = [NSString stringWithFormat:@"%@",IP_Address_IMAGE];
    //分界线的标识符
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
    //根据url初始化request
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10];
    //分界线 --AaB03x
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
    //结束符 AaB03x--
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //要上传的图片
    //    UIImage *image=[params objectForKey:@"pic"];
    //得到图片的data
    CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext(newSize);
    [imageImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* data  = UIImageJPEGRepresentation(newImage, 0.7);
    //http body的字符串
    NSMutableString *body=[[NSMutableString alloc]init];
    //设置HTTPHeader中Content-Type的值
    NSString* content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
    ////添加分界线，换行
    [body appendFormat:@"%@\r\n",MPboundary];
    //声明pic字段，文件名为boris.png
    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
    //声明上传文件的格式
    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    //    [body appendFormat:@"Content-Type: %@\r\n\r\n",content];
    //声明结束符：--AaB03x--
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
    //声明myRequestData，用来放入http body
    NSMutableData *myRequestData=[NSMutableData data];
    //将body字符串转化为UTF8格式的二进制
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    //将image的data加入
    [myRequestData appendData:data];
    //加入结束符--AaB03x--
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *headerUserAgent=@"";
    if ([Common getLoginStatus]) {
        NSString *userName = [[Common getLoginInfo] objectForKey:Key_User_nickname];
        NSString *userId  = [NSString stringWithFormat:@"%@",[[Common getLoginInfo] objectForKey:Key_User_userId]];
        NSString *encryptPwd  = [ [Common getLoginInfo] objectForKey:Key_User_password];
        NSString *localUserIdentify  = [[UIDevice currentDevice].identifierForVendor UUIDString];
        headerUserAgent = [NSString stringWithFormat:@"%@|%@|%@|%@",userName,userId,encryptPwd,localUserIdentify];
    }else{
        headerUserAgent = @"|||";
    }
    
    //设置HTTPHeader
    [request setValue:content forHTTPHeaderField:@"Content-Type"];
    //设置User-Agent
    [request setValue:headerUserAgent forHTTPHeaderField:@"User-Agent"];
    //设置Content-Length
    [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
    //设置http body
    [request setHTTPBody:myRequestData];
    //http method
    [request setHTTPMethod:@"POST"];
    
    //建立连接，设置代理
    //    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    //上传文件开始
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //获得返回值
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    
    //取得返回的图片名
    //    NSArray* array = [returnString componentsSeparatedByString:@"###"];
    //    NSString * image = [NSString stringWithFormat:@"%@", dictionary[@"result"][0][@"simaId"]];
    NSString * image = dictionary[@"title"];
        if (_AddImageButtonOne.selected) {
            if (image.length>0){
                _imageStrOne = image;
            }else{
                _imageStrOne = @"";
            }
        } else if (_AddImageButtonTwo.selected) {
            if (image.length>0){
                _imageStrTwo = image;
            }else{
                _imageStrTwo = @"";
            }
        } else if (_AddImageButtonThree.selected) {
            if (image.length>0){
                _imageStrThree = image;
            }else{
                _imageStrThree = @"";
            }
        } else if (_AddImageButtonFour.selected) {
            if (image.length>0){
                _imageStrFour = image;
            }else{
                _imageStrFour = @"";
            }
        }
    
    
}


#pragma mark - 提交审核
- (IBAction)submit:(id)sender {
    
    if (_nameTextField.text.length==0) {
        [CWHUDTips showTips:_nameTextField.placeholder];
        return;
    }
    if (_phoneNumberTextField.text.length==0) {
        [CWHUDTips showTips:_phoneNumberTextField.placeholder];
        return;
    }
    if (_imageStrOne.length==0) {
        [CWHUDTips showTips:@"请添加身份证正面图片"];
        return;
    }
    if (_imageStrTwo.length==0) {
        [CWHUDTips showTips:@"请添加身份证背面图片"];
        return;
    }
    if (_imageStrThree.length==0) {
        [CWHUDTips showTips:@"请添加从业资格证正面图片"];
        return;
    }
    if (_imageStrFour.length==0) {
        [CWHUDTips showTips:@"请添加从业资格证背面图片"];
        return;
    }
    
    if ([self.muceStatus isEqualToString:@"0"]) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msceMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        
        [dic setObject:self.nameTextField.text forKey:@"muceRealName"];
        [dic setObject:self.phoneNumberTextField.text forKey:@"mucePhone"];
        if (_sexButton.ifSelected) {
            [dic setObject:@"1" forKey:@"muceGender"];
        }else{
            [dic setObject:@"2" forKey:@"muceGender"];
        }
        [dic setObject:_imageStrOne forKey:@"muceIdcardFront"];
        [dic setObject:_imageStrTwo forKey:@"muceIdcardBack"];
        NSString *muceLicence = [NSString stringWithFormat:@"%@,%@",_imageStrThree,_imageStrFour];
        [dic setObject:muceLicence forKey:@"muceLicence"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_addMemberUserCertification withHttpType:@"POST" withTag:JY_JY_addMemberUserCertification];

    } else if ([self.muceStatus isEqualToString:@"2"]) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msceMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        
        [dic setObject:self.nameTextField.text forKey:@"muceRealName"];
        [dic setObject:self.phoneNumberTextField.text forKey:@"mucePhone"];
        if (_sexButton.ifSelected) {
            [dic setObject:@"1" forKey:@"muceGender"];
        }else{
            [dic setObject:@"2" forKey:@"muceGender"];
        }
        [dic setObject:_dic[@"muceIdcardFront"] forKey:@"muceIdcardFront"];
        [dic setObject:_dic[@"muceIdcardBack"] forKey:@"muceIdcardBack"];
        NSString *muceLicence = [NSString stringWithFormat:@"%@,%@",_imageStrThree,_imageStrFour];
        [dic setObject:muceLicence forKey:@"muceLicence"];
        [dic setObject:_dic[@"muceId"] forKey:@"muceId"];
        
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_editMemberUserCertification withHttpType:@"POST" withTag:JY_JY_editMemberUserCertification];
        
    }
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==JY_JY_addMemberUserCertification) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [[Common getNavigation]popViewController];
            
        }
    } else if (tag==JY_JY_editMemberUserCertification) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [[Common getNavigation]popViewController];
            
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}

@end
